/*************************************************************************
	> File Name: P1328.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-02-11 17:49:44
 ************************************************************************/
#include <iostream>
using namespace std;

char result[6][6] = {
    "psyys",
    "ypsys",
    "sypsy",
    "ssypy",
    "yyssp"
};

int a[205], b[205];

int main() {
    int n, na, nb;
    cin >> n >> na >> nb;
    for (int i = 0; i < na; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < nb; i++) {
        cin >> b[i];
    }
    int cnt_a = 0, cnt_b = 0;
    for (int i = 0; i < n; i++) {
        int val_a = a[i % na];
        int val_b = b[i % nb];
        if (result[val_a][val_b] == 'y') cnt_a += 1;
        else if (result[val_a][val_b] == 's') cnt_b += 1;
    }
    cout << cnt_a << " " << cnt_b << endl;
    return 0;
}
